import lombok.SneakyThrows;

import java.io.IOException;
import java.io.ObjectInputStream;
import javax.swing.*;

public class ClientRecv implements Runnable{

    private ChatClient client;
    private ObjectInputStream ois;
    private JTextArea recordPane;
    private boolean isRuned = false;


    public ClientRecv(ChatClient chatClient, ObjectInputStream ois, JTextArea recordPane){
        this.client = chatClient;
        this.ois = ois;
        this.recordPane = recordPane;
    }

    @SneakyThrows
    @Override
    public void run() {
        while (true) {
            try {
                //接收消息
//            System.out.println(ois.readObject());
                recordPane.append(ois.readObject()+ "\n");
            } catch (IOException e) {
                if(!isRuned) {
                    client.exit();
                    isRuned = true;
                }
            }

        }
    }
}